<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.File"%>
<jsp:include page="/common/commonjs.jsp"></jsp:include>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="stylesheet" type="text/css" href="../extjs/ux/fileuploadfield/css/fileuploadfield.css"/>
<script type="text/javascript" src="../extjs/ux/fileuploadfield/FileUploadField.js"></script>

<title>家庭管理管理</title>
</head>
<%
//是否有对应的图片标示
boolean flag = false;
//登陆者的email
String photoName = (String)session.getAttribute("email");
//构建存放图片的位置
String path = application.getRealPath("/")+"resource\\photo";
String fileName = "";
File file = new File(path);
File[] fileList = file.listFiles();
StringBuffer names = new StringBuffer();
for(int i =0; i< fileList.length;i++){
	if(fileList[i].getName().startsWith(photoName)){
		fileName = fileList[i].getName();
		System.out.print(fileName);
		flag = true;
	}
	
}
%>
<body>
<script type="text/javascript">
	Ext.onReady(function(){
		Ext.QuickTips.init();
		Ext.form.Field.prototype.msgTarget = 'side';
		/*
		var fibasic = new Ext.ux.form.FileUploadField({
			id:'uploadFile',
			width:'200'
			});
		*/	
		/*
		var photoForm = new Ext.form.FormPanel({
		  labelWidth: 75, // label settings here cascade unless overridden
	        frame:true,  
	      	bodyStyle:'padding:5px;',
	        labelAlign: 'right',
	        items: {  
	            xtype:"textfield",  
	            fieldLabel:"个人照片", 
	            id:'selfphoto', 
	            width:170,  
	            height:177,  
	            inputType:"image"  
	        }
	});
	*/	
		var	uploadForm = new Ext.form.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,  
        fileUpload : true, 
      	bodyStyle:'padding:5px;',
        labelAlign: 'right',
        buttonAlign :'center',
      //  enctype:"multipart/form-data",
        items: [{  
	            xtype:"textfield",  
	            fieldLabel:"个人照片", 
	            id:'selfphoto', 
	            width:170,  
	            height:177,  
	            inputType:"image"  
	        },{ 
            xtype : 'fileuploadfield',  
           //xtype:"textfield",  
           	id:"upload",
            fieldLabel : '选择图片', 
            width:200, 
            name : 'upload',  
            allowBlank : true,  
            buttonText : '浏览'
            }
        ],

        buttons : [ {  
            text : '保存',  
            handler : function() {  
                var form = uploadForm.getForm();
               	var uploadFileName = Ext.getCmp('upload').getValue();
               	var seprate = uploadFileName.split('.');
               	var types = new Array('jpg','bmp','png');
               	var type = seprate[1];
               	var flag = false;
               	for(i=0;i<types.length;i++){
                   	if (types[i] == type){
                       	flag = true;
                       	}
                   	}
               	if(flag){
                form.submit({
                     url : 'fileupload.action',  
                     waitMsg: '正在上传...',  
                     ////{"resultMsg":"ok","success":true}
                     failure : function (form,action){  
            		Ext.Msg.alert('上传成功','请重新进入查看');}
            		}); 
                }else{
					Ext.Msg.alert("提示","请选择正确的图片格式!\n包括jpg bmp png格式");
                }
            }  
        } ]  
    });

		
	
	 var win = new Ext.Window({
		title: '个人照片',
		closable:false,
        width: 380,
        height:300,
        layout: 'fit',
        plain:true,
        defaults : {scope : this}, 
        items:[uploadForm]
	 }).show();
	 
	 if(<%=flag%>){
		 Ext.getDom('selfphoto').src="../resource/photo/<%=fileName%>";
		}else{
		Ext.getDom('selfphoto').src="../resource/photo/default.jpg";
		}
	}		
	);
	</script>
</body>
</html>